package org.xjtu.weteam.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xjtu.weteam.common.utils.TokenUtils;
import org.xjtu.weteam.mapper.InfoMapper;
import org.xjtu.weteam.model.domain.Info;
import org.xjtu.weteam.model.dto.InfoDTO;
import org.xjtu.weteam.service.InfoService;

import java.util.List;

@Service
public class InfoServiceImpl extends ServiceImpl<InfoMapper, Info> implements InfoService {
    @Autowired
    private InfoMapper infoMapper;
    @Override
    public List<Info> selectInfoByUserId(String token){
        return infoMapper.selectInfoByUserId(TokenUtils.getIdFromToken(token));
    }

    @Override
    public boolean haveReadMessage(Integer id) {
        int row=infoMapper.haveReadMessage(id);
        System.out.println("已读行数："+row);
        return row>0;
    }

    @Override
    public boolean removeInfoById(Integer id) {
        int row=infoMapper.removeInfoById(id);
        System.out.println("删除行数："+row);
        return row>0;
    }

    @Override
    public boolean sendMessage(InfoDTO info) {
        int row=infoMapper.sendMessage(info.getTitle(),info.getNote(),info.getUserId());
        System.out.println("添加行数："+row);
        return row>0;
    }

    ;
}
